<div class="layui-tab layui-tab-brief" lay-filter="demo" lay-allowclose="true">
    <ul class="layui-tab-title">
        <li class="layui-this" lay-id="11">角色权限管理</li>
    </ul>
    <!--<form class="layui-form" action="">-->
        <!--<div class="layui-tab-content">-->
            <!--<div class="layui-tab-item layui-show">-->
                <!--<div class="layui-form-item">-->
                    <!--<label class="layui-form-label">角色</label>-->
                    <!--<div class="layui-input-block" style="width: 450px">-->
                        <!--<select name="rid" id="rolename" lay-filter="aihao">-->
                        <!--</select>-->
                    <!--</div>-->
                <!--</div>-->
                <!--<div style="margin-left: 109px"><table id = "menuInfo" lay-filter="menuInfo"></table></div>-->
                <!--<div class="layui-form-item">-->
                    <!--<div class="layui-input-block">-->
                        <!--<button class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
    <!--</form>-->
    <form class="layui-form">
        <div class="layui-tab-content">
            <div class="layui-form-item">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-block" style="width: 450px">
                    <select name="rid" id="rolename" lay-filter="aihao">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择权限</label>
                <div class="layui-input-block">
                    <div id="LAY-auth-tree-index"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" type="submit">保存</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    menu.getMenuList();
</script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        $.ajax({
            type:"GET",
            url:"/role/notadmin/list",
            async:false,
            success:function (data) {
                for(var i = 0;i<data.data.length;i++){
                    var val = data.data[i].name;
                    var id = data.data[i].id;
                    var opt = "<option value='"+ id +"'>"+ val +"</option>"
                    $("#rolename").append(opt);
                    form.render();
                }
            }
        });

        //监听提交
//        form.on('submit(demo1)', function(data){
//            var da = data.field;
//            console.log(da);
//            return false;
//        });
    });
</script>
<script>
//    layui.config({
//        base: '',
//    }).extend({
//        authtree: 'menu',
//    });
    layui.use(['jquery', 'form'], function(){
        var $ = layui.jquery;
//        var authtree = layui.authtree;
        var form = layui.form;
        $.ajax({
            url: '/admin/tree',
//            dataType: 'json',
            success: function(data){
                console.log(data);
                // 渲染时传入渲染目标ID，树形结构数据（具体结构看样例，checked表示默认选中），以及input表单的名字
                menu.getRoleMenu().menurender('#LAY-auth-tree-index', data.data.trees, {inputname: 'authids[]', layfilter: 'lay-check-auth', openall: false});

                // 监听自定义lay-filter选中状态，PS:layui现在不支持多次监听，所以扩展里边只能改变触发逻辑，然后引起了事件冒泡延迟的BUG，要是谁有好的建议可以反馈我
                form.on('checkbox(lay-check-auth)', function(data){
                    // 注意这里：需要等待事件冒泡完成，不然获取叶子节点不准确。
                    setTimeout(function(){
                        // 获取选中的叶子节点
                        var leaf = menu.getRoleMenu().getLeaf('#LAY-auth-tree-index');
                        console.log(leaf);
                    }, 100);
                });
            }
        })
    });
</script>
